package com.lots.controller.user;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

/**
 * AI功能控制器
 */
@RestController
@Slf4j
@RequestMapping("/ai")
@Tag(name = "AI智能助手相关接口")
public class AiController {
    
    @Autowired
    private ChatClient dashScopeChatClient;


    /**
     * 简单AI对话接口
     */
    @GetMapping("/chat")
    @Operation(summary = "简单AI对话", description = "与AI助手进行简单对话")
    public Flux<String> simpleChat(
            @Parameter(description = "用户问题", example = "你好，很高兴认识你，能简单介绍一下自己吗？")
            @RequestParam(value = "message") String message,HttpServletResponse response) {

        log.info("收到AI对话请求：{}", message);
        response.setCharacterEncoding("UTF-8");
        return dashScopeChatClient.prompt(message).stream().content();
    }

}